﻿using SdtpsBase;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace sdtpstest
{
    public class test : ITaskEngine
    {
        public global::GRPCClass.TaskRequest taskrequest
        {
            get;
            set;
        }
        public global::GRPCClass.TaskReply taskteply
        {
            get;
            set;
        }

        public event EventHandler TaskFinish;

        public global::GRPCClass.TaskReply execture(global::GRPCClass.TaskRequest value)
        {
            this.taskrequest = value;
            string json= Newtonsoft.Json.JsonConvert.SerializeObject(value);
            string path = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "tasktest.log");
            //文件存放路径，保证文件存在。 
            using (StreamWriter sw = new StreamWriter(path, true))
            {
                sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH;mm:ss"));
                sw.WriteLine(json);
                sw.Close();
            }
            GRPCClass.TaskReply mytr = new GRPCClass.TaskReply();
            mytr.ID = value.ID;
            mytr.TaskInfo = value;
            mytr.Message = "成功";
            value.EndTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            mytr.Status = 2;
            this.taskteply = mytr;
            if (TaskFinish != null)
            {
                this.TaskFinish(this, new EventArgs());
            }
            return mytr;
        }
    }
}
